package com.example.demo.api;

import cn.hutool.extra.spring.SpringUtil;
import com.example.demo.dao.Demo2Mapper;
import com.example.demo.test.ModuleApplication;
import lombok.SneakyThrows;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * @author 张述江
 * @date 2023-08-24
 */
@RestController
@RequestMapping("api")
public class Demo2Controller {

    @Resource
    private Demo2Mapper demo2Mapper;

    @Value("${dynamic.jar:/}")
    private String dynamicJar;

    @Resource
    private ModuleApplication moduleApplication;

    @GetMapping("demo2")
    public List<Map<String, Object>> demo2() {
        System.out.println("demo2的接口");
        return demo2Mapper.query();
    }

    @SneakyThrows
    @GetMapping("load")
    public String load() {
        moduleApplication.reloadJar(new File(dynamicJar).toURI().toURL());
        return "加载成功";
    }
}
